package com.findviewbydream.evil.eda.Utils;

import android.Manifest;
import android.app.Activity;
import android.content.Context;

import com.findviewbydream.evil.eda.Utils.Dialog.CustomMaterialDialog;
import com.mylhyl.acp.Acp;
import com.mylhyl.acp.AcpListener;
import com.mylhyl.acp.AcpOptions;

import java.util.List;

/********************************************
 * 工程名：Eda
 * 包名：com.findviewbydream.evil.eda.Utils
 * 时间：16-7-9 上午12:10
 * 作者：白雨濃 evil
 * 邮箱：evilbai@foxmail.com
 * 内容：权限获取封装类
 ********************************************/
public abstract class SAcp
{
    public abstract void onGranteds();

    public abstract void onDenieds();

    public void getPermissions(String[] permissions)
    {
        Acp.getInstance(Utils.getContext()).request(new AcpOptions.Builder()
                        .setPermissions(permissions).build()
                , new AcpListener()
                {
                    @Override
                    public void onGranted()
                    {
                        onGranteds();
                    }

                    @Override
                    public void onDenied(List<String> permissions)
                    {
                        onDenieds();
                    }
                });
    }

    public void getPermissions(String permission)
    {
        Acp.getInstance(Utils.getContext()).request(new AcpOptions.Builder()
                        .setPermissions(new String[]{permission}).build()
                , new AcpListener()
                {
                    @Override
                    public void onGranted()
                    {
                        onGranteds();
                    }

                    @Override
                    public void onDenied(List<String> permissions)
                    {
                        onDenieds();
                    }
                });
    }

    public static void showDialog(Context context, final Activity activity)
    {
        final CustomMaterialDialog dialog = new CustomMaterialDialog(context);
        dialog.setMessage("权限获取失败,3秒后将退出软件!\n请稍后重试!")
                .setCanBack(false)
                .show();


        new Utils.SHandler()
        {
            @Override
            public void handler()
            {
                dialog.dismiss();
                activity.finish();
            }
        }.start(3000);
    }


}
